<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function myNew(GouzaoFunction, ...args) {

            // 这里输出Person {name: 'quan', age: 23}
            let obj = Object.create(GouzaoFunction.prototype)

            // Object.create里面实际就是
            // 但是输出的时候，不一样F {name: 'quan', age: 23}
            // function F() { }
            // F.prototype = GouzaoFunction.prototype
            // let obj = new F()

            let result = GouzaoFunction.apply(obj, args)
            return typeof result === 'object' ? result : obj
        }
        function Person(name, age) {
            this.name = name
            this.age = age
        }
        Person.prototype.sayName = function () {
            console.log(this.name)
        }
        let instance1 = myNew(Person, 'quan', 23)
        console.log(instance1)
        instance1.sayName()
        console.log(instance1.age)
    </script>
</body>

</html>